package yx.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.CertificateServiceInt;
import yx.vo.CertificateVO;
import yx.vo.JsonVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "certificateAction")
public class CertificateAction extends BaseAction implements ModelDriven<CertificateVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(CertificateAction.class);

	private CertificateVO certificate = new CertificateVO();

	@Override
	public CertificateVO getModel() {
		return certificate;
	}

	private CertificateServiceInt certificateService;

	public CertificateServiceInt getCertificateService() {
		return certificateService;
	}

	@Autowired
	public void setCertificateService(CertificateServiceInt certificateService) {
		this.certificateService = certificateService;
	}

	public void queryCertificate() {
		super.writeJson(certificateService.datagrid(certificate));
	}

	public void addCertificate() {
		JsonVO j = new JsonVO();
		try {
			CertificateVO u = certificateService.save(certificate);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removeCertificate() {
		certificateService.remove(certificate.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editCertificate() {
		CertificateVO u = certificateService.edit(certificate);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

}
